import time

from selenium import webdriver

from ..exception.TestException import TestException
from ..common.ui.Selector import Selector
from .Combotree import Combotree

import pytest


def test_set_value():
    browser = webdriver.Chrome()
    browser.maximize_window()
    browser.get("https://fish.iwhalecloud.com/fish-desktop/examples/combotree/index.html")
    time.sleep(2)
    try:
        combotree = Combotree(browser, 'citySel', Selector.ID)
        combotree.setValue('石家庄')
        time.sleep(2)
        value = combotree.getValue()
        assert '石家庄' == value['name']
    finally:
        browser.close()


def test_set_value_no_data():
    browser = webdriver.Chrome()
    browser.maximize_window()
    browser.get("https://fish.iwhalecloud.com/fish-desktop/examples/combotree/index.html")
    time.sleep(2)
    try:
        combotree = Combotree(browser, 'citySel', Selector.ID)
        with pytest.raises(TestException):
            combotree.setValue('石家庄22222222')
        time.sleep(2)
    finally:
        browser.close()


if __name__ == '__main__':
    pytest.main(['-s', 'Combotree_test.py'])
